import { createBrowserRouter } from 'react-router-dom'

import Login from '@/pages/Login'
import Layout from '@/pages/Layout'
import AuthRoute from '@/components/AuthRoute.js'
// import Publish from '@/pages/Publish'
// import Article from '@/pages/Article'
// import Home from '@/pages/Home'
import { Suspense, lazy } from 'react'

const Home = lazy(() => import('@/pages/Home'))
const Article = lazy(() => import('@/pages/Article'))
const Publish = lazy(() => import('@/pages/Publish'))

// 别忘了 设置二级路由出口

const router = createBrowserRouter([
  {
    path: '/',
    element: <AuthRoute><Layout /></AuthRoute>,
    children: [
      {
        index: true, //设置成默认渲染组件
        element: <Suspense fallback = {'加载中'}> <Home /> </Suspense> , //内置组件
      },
      {
        path: 'article',
        element: <Suspense fallback = {'加载中'}> <Article /> </Suspense> ,
      },
      {
        path: 'publish',
        element: <Suspense fallback = {'加载中'}> <Publish /> </Suspense>,
      },
    ],
  },
  {
    path: '/login',
    element: <Login />,
  },
])

export default router
